package com.onefish.toolkit.core;

import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;

public class ly {
    public static void main(String[] args) throws Exception {
        String str = "Hell\\, World!";
        char targetChar = '\\';
        char replacementChar = '/';

        // 使用 replace() 方法批量替换指定字符
        String replacedStr = str.replace(targetChar, replacementChar);

        System.out.println("原始字符串：" + str);
        System.out.println("替换后的字符串：" + replacedStr);
//        String source = "C:\\Users\\Administrator\\Desktop\\test";
//        System.out.println("source = " + source);
//        String str = "C:\\Users\\Administrator\\Desktop\\test\\一级文件夹\\二级文件夹\\二级文件夹下的文件.txt";
//        Path base = Paths.get(source);
//        Path des = Paths.get(str);
//        Path relativePath = base.relativize(des);
//        System.out.println(relativePath.toString());
//        int index = source.lastIndexOf("\\");
//        String lastStr = source.substring(index+1);
//        System.out.println("lastStr = " + lastStr);
//        String folderPath = "C:\\Users\\Administrator\\Desktop\\test.txt";
//        // 遍历文件夹及其子文件
//        Files.walkFileTree(Paths.get(folderPath), new SimpleFileVisitor<Path>() {
//            @Override
//            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
//                // 删除文件
//                Files.delete(file);
//                System.out.println("Deleted file: " + file);
//                return FileVisitResult.CONTINUE;
//            }
//
//            @Override
//            public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
//                // 删除文件夹
//                Files.delete(dir);
//                System.out.println("Deleted directory: " + dir);
//                return FileVisitResult.CONTINUE;
//            }
//        });
    }
}
